import React, {Component} from 'react';

export default class App extends Component {
    render() {
        return (
            <div>
                app
            </div>
        );
    }
}

var bus = {
    list: [],
    //订阅
    subscribe(callback) {
        console.log(callback)
        this.list.push(callback)
    },

    //发布
    publish(item) {
        //遍历所有list,将回调函数执行
        this.list.forEach(callback=>{
            callback && callback(item)
        })
    },
}

//订阅者
bus.subscribe((val) => {
    console.log(111,val)
})

bus.subscribe((val) => {
    console.log(222,val)
})

bus.subscribe((val) => {
    console.log(333,val)
})

//发布者
bus.publish('哈哈哈')
